package cn.demoncat.util.web.constant;

import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * HTTP用户代理（浏览器和设备信息）常量
 * 
 * @author 延晓磊
 *
 * @since 2019年9月9日
 */
public class AgentConstant {

	/**
	 * 全部系统名称
	 */
	public static final Set<String> SYSTEM_ALL = getAllSystem();
	/**
	 * 根系统名称
	 */
	public static final Set<String> SYSTEM_ROOT = getRootSystem();
	/**
	 * 全部浏览器名称
	 */
	public static final Set<String> BROWSER_ALL = getAllBrowser();
	/**
	 * 根浏览器名称
	 */
	public static final Set<String> BROWSER_ROOT = getRootBrowser();
	
	/**
	 * 设备类型
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年9月10日
	 */
	public static final class SystemType {

		/**
		 * 电脑
		 */
		public static final String COMPUTER = "Computer";

		/**
		 * 手机
		 */
		public static final String MOBILE = "Mobile";

		/**
		 * 平板
		 */
		public static final String TABLET = "Tablet";

		/**
		 * 游戏机
		 */
		public static final String GAME_CONSOLE = "Game console";

		/**
		 * 数字电视
		 */
		public static final String DMR = "Digital media receiver";

		/**
		 * 智能手表、眼镜
		 */
		public static final String WEARABLE = "Wearable computer";

		/**
		 * 未知
		 */
		public static final String UNKNOWN = "Unknown";

		/**
		 * 映射
		 */
		public static final Map<String, String> MAP = new LinkedHashMap<String, String>() {
			private static final long serialVersionUID = 1L;
			{
				put(COMPUTER, "电脑");
				put(MOBILE, "手机");
				put(TABLET, "平板电脑");
				put(GAME_CONSOLE, "游戏机");
				put(DMR, "数字电视");
				put(WEARABLE, "智能设备");
				put(UNKNOWN, "未知");
			}
		};

		/**
		 * 映射 - CODE
		 */
		public static final Map<String, String> MAP_CODE = new LinkedHashMap<String, String>() {
			private static final long serialVersionUID = 1L;
			{
				put(COMPUTER, "1");
				put(MOBILE, "2");
				put(TABLET, "3");
				put(GAME_CONSOLE, "4");
				put(DMR, "5");
				put(WEARABLE, "6");
				put(UNKNOWN, "0");
			}
		};
	}

	/**
	 * 浏览器类型
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年9月10日
	 */
	public static final class BrowserType {

		/**
		 * 浏览器
		 */
		public static final String BROWSER = "Browser";

		/**
		 * 手机浏览器
		 */
		public static final String MOBILE_BROWSER = "Browser (mobile)";

		/**
		 * 文本浏览器
		 */
		public static final String TEXT_BROWSER = "Browser (text only)";

		/**
		 * 邮箱客户端
		 */
		public static final String EMAIL_CLIENT = "Email Client";

		/**
		 * 爬虫
		 */
		public static final String ROBOT = "Robot";

		/**
		 * 下载工具
		 */
		public static final String TOOL = "Downloading tool";

		/**
		 * APP
		 */
		public static final String APP = "Application";

		/**
		 * 未知
		 */
		public static final String UNKNOWN = "unknown";

		/**
		 * 映射
		 */
		public static final Map<String, String> MAP = new LinkedHashMap<String, String>() {
			private static final long serialVersionUID = 1L;
			{
				put(BROWSER, "浏览器");
				put(MOBILE_BROWSER, "手机浏览器");
				put(TEXT_BROWSER, "文本浏览器");
				put(EMAIL_CLIENT, "邮箱客户端");
				put(ROBOT, "爬虫");
				put(TOOL, "下载工具");
				put(APP, "APP");
				put(UNKNOWN, "未知");
			}
		};

		/**
		 * 映射-CODE
		 */
		public static final Map<String, String> MAP_CODE = new LinkedHashMap<String, String>() {
			private static final long serialVersionUID = 1L;
			{
				put(BROWSER, "1");
				put(MOBILE_BROWSER, "2");
				put(TEXT_BROWSER, "3");
				put(EMAIL_CLIENT, "4");
				put(ROBOT, "5");
				put(TOOL, "6");
				put(APP, "7");
				put(UNKNOWN, "0");
			}
		};
	}
	
	
	
	
	
	
	/**
	 * 全部系统名称
	 * 
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年9月10日
	 */
	private static Set<String> getAllSystem(){
		Set<String> list = new HashSet<>();
		for (OperatingSystem system : OperatingSystem.values()) {
			list.add(system.getName());
		}
		return list;
	}
	/**
	 * 根系统名称
	 * 
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年9月10日
	 */
	private static Set<String> getRootSystem(){
		Set<String> list = new HashSet<>();
		for (OperatingSystem system : OperatingSystem.values()) {
			list.add(system.getName());
		}
		return list;
	}
	
	/**
	 * 全部浏览器名称
	 * 
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年9月10日
	 */
	private static Set<String> getAllBrowser(){
		Set<String> list = new HashSet<>();
		for (Browser browser : Browser.values()) {
			list.add(browser.getName());
		}
		return list;
	}
	/**
	 * 根浏览器名称
	 * 
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年9月10日
	 */
	private static Set<String> getRootBrowser(){
		Set<String> list = new HashSet<>();
		for (Browser browser : Browser.values()) {
			if (browser.getGroup().equals(browser)) {
				list.add(browser.getName());
			}
		}
		return list;
	}
	
}
